package cn.yllr.tomgxianghui.service.impl;

import cn.yllr.tomgxianghui.entity.Dishes;
import cn.yllr.tomgxianghui.dao.DishesDao;
import cn.yllr.tomgxianghui.model.ShopCart;
import cn.yllr.tomgxianghui.service.DishesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Dishes)表服务实现类
 *
 * @author makejava
 * @since 2021-12-21 19:49:44
 */
@Service("dishesService")
public class DishesServiceImpl implements DishesService {
    @Resource
    private DishesDao dishesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param foodid 主键
     * @return 实例对象
     */
    @Override
    public Dishes queryById(Integer foodid) {
        return this.dishesDao.queryById(foodid);
    }

    @Override
    public Dishes queryByName(String name) {
        return this.dishesDao.queryByName(name);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Dishes> queryAllByLimit(int offset, int limit) {
        return this.dishesDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param dishes 实例对象
     * @return 实例对象
     */
    @Override
    public Dishes insert(Dishes dishes) {
        this.dishesDao.insert(dishes);
        return dishes;
    }

    /**
     * 修改数据
     *
     * @param dishes 实例对象
     * @return 实例对象
     */
    @Override
    public Dishes update(Dishes dishes) {
        this.dishesDao.update(dishes);
        return this.queryById(dishes.getFoodid());
    }

    /**
     * 通过主键删除数据
     *
     * @param foodid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer foodid) {
        return this.dishesDao.deleteById(foodid) > 0;
    }

    @Override
    public List<Dishes> findAllDishes() {
        return this.dishesDao.findAllDishes();
    }

    @Override
    public List<ShopCart> queryDishesByUserID(String account) {
        return this.dishesDao.queryDishesByUserID(account);
    }

    @Override
    public List<Dishes> queryDishesByName(String name) {
        String key ="%"+name+"%";
        return this.dishesDao.queryDishesByName(key);
    }

    @Override
    public List<Dishes> queryDishesRecommend(int count) {
        return this.dishesDao.queryDishesRecommend(count);
    }
}